package project.tests;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.GridLayout;
import javax.swing.JTextField;
import javax.swing.JButton;

import project.map.OccupancyGridMap;
import project.map.Position;
import project.robot.*;
import project.robot.navigation.ChessGridNavigator;
import project.simulador.*;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import lejos.robotics.navigation.Navigator;


public class HIMMtest extends JFrame {

	private JPanel contentPane;
	private JTextField txtDistancia;
	private JTextField txtAngulo;
	private JTextField txtPosicionX;

	private ChessGridNavigator navegador;
	private Robot robot;
	private OccupancyGridMap map;
	private JTextField txtPosicionY;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					HIMMtest frame = new HIMMtest();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public HIMMtest() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 507, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));

		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.WEST);
		panel.setLayout(new GridLayout(0, 2, 0, 0));

		JLabel lblNewLabel = new JLabel("Distancia:");
		panel.add(lblNewLabel);

		txtDistancia = new JTextField();
		panel.add(txtDistancia);
		txtDistancia.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel("Angulo:");
		panel.add(lblNewLabel_1);

		txtAngulo = new JTextField();
		panel.add(txtAngulo);
		txtAngulo.setColumns(10);

		JLabel lblNewLabel_2 = new JLabel("Posicion X");
		panel.add(lblNewLabel_2);

		txtPosicionX = new JTextField();
		panel.add(txtPosicionX);
		txtPosicionX.setColumns(10);
		
		JLabel lblPosicionY = new JLabel("Posicion Y");
		panel.add(lblPosicionY);
		
		txtPosicionY = new JTextField();
		txtPosicionY.setColumns(10);
		panel.add(txtPosicionY);

		JPanel panel_1 = new JPanel();
		contentPane.add(panel_1, BorderLayout.EAST);
		panel_1.setLayout(new GridLayout(9, 1, 0, 0));

		JPanel panel_2 = new JPanel();
		panel_1.add(panel_2);

		JPanel panel_3 = new JPanel();
		panel_1.add(panel_3);

		JPanel panel_5 = new JPanel();
		panel_1.add(panel_5);
		
		JPanel panel_6 = new JPanel();
		panel_1.add(panel_6);
		
		JPanel panel_7 = new JPanel();
		panel_1.add(panel_7);

		JPanel panel_4 = new JPanel();
		contentPane.add(panel_4, BorderLayout.CENTER);
		
				JButton btnReset = new JButton("Reset");
				btnReset.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						btnReset();
					}
				});
				
				JButton btnStartDetection = new JButton("Start Detection");
				btnStartDetection.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						
						int range =Integer.parseInt(txtDistancia.getText());
						
						Position pos = new Position();
						pos.angle=(Double.parseDouble(txtAngulo.getText()));
						pos.x=Integer.parseInt(txtPosicionX.getText());
						pos.y=Integer.parseInt(txtPosicionY.getText());
						
						ArrayList<Position> lista = new ArrayList<Position>();
							
						HimmMapUpdater.UpdateMap(map, range,pos, lista,80);
					}
				});
				panel_4.add(btnStartDetection);
				panel_4.add(btnReset);

		inicializar();
	}

	private void inicializar()
	{
	
	}

	private void btnReset()
	{
		map = new OccupancyGridMap(8,9);
	}
	
	
}
